package com.ssyt.hiring.company.service;

import java.util.List;

import org.apache.commons.lang3.Validate;

import com.ssyt.hiring.common.util.DBUtil;
import com.ssyt.hiring.company.entity.CompanyEntity;

/**
 * CompanyDao
 * 
 * @author Administrator
 *
 */
public class CompanyService {

	/**
	 * 企业登录
	 * 
	 * @param code
	 * @param password
	 * @return
	 */
	public CompanyEntity login(String code, String password) {
		String sql = "SELECT * FROM company WHERE code=? AND password=? LIMIT 1";
		return DBUtil.getUniqueResult(CompanyEntity.class, sql, code, password);
	}

	/**
	 * 企业注册
	 * 
	 * @param list
	 * @return
	 */
	public int add(List<Object> list) {
		String sql = "INSERT INTO company values(NUll,?,?,?,?,?,?,?,?,?)";
		return DBUtil.executeUpdate(sql, list);
	}

	/**
	 * 修改密码
	 * 
	 * @param oldPassword
	 * @param newPassword
	 * @return
	 */
	public int updatePwd(String oldPassword, String newPassword, int id) {
		String sql = "UPDATE company SET password=? WHERE id=? AND password=?";
		return DBUtil.executeUpdate(sql, newPassword, id, oldPassword);
	}

	/**
	 * 按id查询企业信息
	 * 
	 * @param id
	 * @return
	 */
	public CompanyEntity preUpdate(int id) {
		String sql = "SELECT * FROM company WHERE id=?";
		return DBUtil.getUniqueResult(CompanyEntity.class, sql, id);
	}

	/**
	 * 修改企业信息
	 * 
	 * @param list
	 * @return
	 */
	public int update(List<Object> list) {
		String sql = "UPDATE company SET name=?,email=?,phone=?,linkman=?,address=?,numbers=?,slogan=? WHERE id=?";
		return DBUtil.executeUpdate(sql, list);
	}

	/**
	 * 按帐号查询信息
	 * 
	 * @param code
	 * @return
	 */
	public CompanyEntity queryByCode(String code) {
		Validate.notBlank(code, "参数code不能为空", code);
		return DBUtil.getUniqueResult(CompanyEntity.class,
				"SELECT * FROM company WHERE code=? LIMIT 1", code);
	}
}
